from concurrent.futures import ThreadPoolExecutor

import time

def get_html(times):
    time.sleep(times)
    print(f'get page {times} success')
    return times

executor = ThreadPoolExecutor(max_workers=1)
#通过submit函数提交执行的函数到线程池中，返回一个future对象，submit 是立即返回
task1 = executor.submit(get_html, (2))
task2 = executor.submit(get_html, (3))

#done方法用于判定某个任务是否完成
print(task1.done())#判断是否执行成功
time.sleep(3)
print(task1.done())

#result方法可以获取task的执行结果
print(task1.result())
